//
//  DiskDataTableViewCell.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/4/26.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class DiskDataTableViewCell: BaseTableViewCell {
    lazy var diskLabel:UILabel = {
      let label  = BaseLabel(style: .twiceStyle)
        label.font = UIFont.systemFont(ofSize: isiphone5S() ? 9 : 11)
      return label
    }()
    
    lazy var backView:UIView = {
       let view = UIView()
        return view
    }()
    
    lazy var priceLabel:UILabel = {
        let label  = UILabel()
        label.textAlignment = NSTextAlignment.right
        label.font = UIFont.systemFont(ofSize: isiphone5S() ? 9 : 11)
        label.textColor = kThemeColor
        return label
    }()
    
    lazy var numberLabel:UILabel = {
        let label  = BaseLabel(style: .twiceStyle)
        label.font = UIFont.systemFont(ofSize: isiphone5S() ? 9 : 11)
        label.textAlignment = NSTextAlignment.right
        return label
    }()
    
    override func setUpUI() {
        self.contentView.addSubview(diskLabel)
        diskLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        self.contentView.addSubview(priceLabel)
       
        
        priceLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(isiphone5S() ? -60 : -70)
            make.centerY.equalToSuperview()
            make.width.lessThanOrEqualTo(kSCREEN_WIDTH*0.4 + (isiphone5S() ? -80 : -90))
        }
        
        self.contentView.addSubview(numberLabel)
        numberLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(isiphone5S() ? -5 : -15)
            make.centerY.equalToSuperview()
            make.width.lessThanOrEqualTo(50)
        }
        
        self.contentView.addSubview(backView)
       backView.frame = CGRect(x: Double(kSCREEN_WIDTH*0.4), y: 0, width: 0, height: 25)
        
    }
    func setModel(model:DepdetailModel,isUp:Bool,bigNumber:String) {
        let length = Double(model.number)! / Double(bigNumber)!
        UIView.animate(withDuration: 0.5) {
            let x = Double(kSCREEN_WIDTH*0.4) - Double(length) * Double(kSCREEN_WIDTH*0.4)
            let frame = CGRect(x: x, y: 0, width: Double(length) * Double(kSCREEN_WIDTH*0.4), height: 25)
            if !frame.midX.isNaN {
                self.backView.frame = CGRect(x: x, y: 0, width: Double(length) * Double(kSCREEN_WIDTH*0.4), height: 25)
            }else {
                self.backView.frame = CGRect(x: Double(kSCREEN_WIDTH*0.4), y: 0, width: 0, height: 25)
            }
        }
        self.priceLabel.text = model.price
        if model.number.count != 0 {
            if Double(model.number)! >= 1000.00 {
                self.numberLabel.text = CYCalculate.cy_dividing(firstNumber: model.number, lastNumber: 1000.00, digit: 3) + "k"
            }else {
                self.numberLabel.text = model.number
            }
        }else {
            self.numberLabel.text = ""
        }
        
        self.backView.backgroundColor = isUp ? UIColor(hexStr:"#eb4949").withAlphaComponent(0.1) : UIColor(hexStr:"#3cb265").withAlphaComponent(0.1)
    
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
